<script setup>
import { useTodoStore } from '../store/todos';

const todos = useTodoStore()

todos.$subscribe(()=>{
  localStorage.setItem('todoList',JSON.stringify(todos.list))
})
</script>

<template>
  <section class="main">
    <input id="toggle-all" class="toggle-all" type="checkbox" @change="todos.changeAll(!todos.isAll)" :checked='todos.isAll'/>
    <label for="toggle-all">Mark all as complete</label>
    <ul class="todo-list">
      <li :class="{completed : item.done}" v-for="item in todos.showList" :key="item.id" @change="todos.changeDone(item.id)">
        <div class="view">
          <input class="toggle" type="checkbox" :checked="item.done" />
          <label>{{item.name}}</label>
          <button class="destroy" @click="todos.del(item.id)"></button>
        </div>
        <input class="edit" value="Create a TodoMVC template" />
      </li>
      <!-- <li>
        <div class="view">
          <input class="toggle" type="checkbox" />
          <label>Buy a unicorn</label>
          <button class="destroy"></button>
        </div>
        <input class="edit" value="Rule the web" />
      </li> -->
    </ul>
  </section>
</template>

<style lang="less" scoped></style>
